import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2024-11-01
 * Time: 17:19
 */
public class Bignum {

    public static String addStrings(String s1, String s2) {
        int i = s1.length() - 1, j = s2.length() - 1, count= 0;
        StringBuffer sb= new StringBuffer();
        while (i >= 0 || j >= 0 || count != 0) {
            int x = i >= 0 ? s1.charAt(i) - '0' : 0;
            int y = j >= 0 ? s2.charAt(j) - '0' : 0;
            int res = x + y + count;
            sb.append(res % 10);
            count= res / 10;
            i--;
            j--;
        }
        // 计算完以后的答案需要翻转过来
        sb.reverse();
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println("5746823"+"+547877646="+addStrings("5746823", "547877646"));
    }
}
